
$(function () {
    // tab切换
    let $teb = $('.tab a')
    let newsList = $('.news_list')
    $teb.click(function () {
        var index = $(this).index();
        $teb.each(function () {
            $(this).removeClass("active");
        });
        $teb.eq(index).addClass("active");
        newsList.each(function () {
            $(this).removeClass('show');
        });
        newsList.eq(index).addClass('show');
    });

    // 顶部轮播图
    const $banner = $('.banner')
    const $carousel = $('#carousel_1')
    const $ul = $('#carousel_1>ul')
    const $span = $('#carousel_1 .carousel-indicators>span')
    const $box = $('#carousel_1 .currentBox')
    const $prev = $('#carousel_1>.currentBox>.carousel-prev-btn')
    const $next = $('#carousel_1>.currentBox>.carousel-next-btn')

    $ul.append($('#carousel_1>ul>li').first().clone());

    const $lis = $('#carousel_1>ul>li')

    let index = 0;

    let timeId = setInterval(nextClick, 3000);

    $banner.hover(function () {

        clearInterval(timeId);
    }, function () {
        timeId = setInterval(nextClick, 3000);
    })

    // 右箭头
    $next.click(nextClick);
    function nextClick() {
        index++;

        if (index == $lis.length) {
            index = 1;
            $ul.css({ left: 0 });
        }

        $ul.stop().animate({ left: -index * $lis.width() });
        $span.eq(index == $lis.length - 1 ? 0 : index).addClass('active').siblings().removeClass('active');
    }
    // 左箭头
    $prev.click(function () {
        index--;
        if (index < 0) {
            index = $lis.length - 2;

            $ul.css({ left: -($lis.length - 1) * $lis.width() });
        }
        $ul.stop().animate({ left: -index * $lis.width() });
        $span.eq(index).addClass('active').siblings().removeClass('active');
    });

    // 点击圆点
    $span.click(function () {
        $(this).addClass('active').siblings().removeClass('active');
        index = $(this).index();
        $ul.stop().animate({ left: -index * $lis.width() });
    })



    // 热度资讯轮播图
    let $bannerLeft = $('.banner_left')
    let $carousel_02 = $('#carousel_02')
    let $uls = $('#carousel_02>ul')
    // let $list = $('#carousel_02>ul>li')
    let $spans = $('#carousel_02 .carousel-indicators>span')
    const $divs = $('#carousel_02 currentBox')
    const $left = $('#carousel_02 currentBox>.carousel-prev-btn')
    const $right = $('#carousel_02 currentBox>.carousel-prev-btn')

    $uls.append($('#carousel_02>ul>li').first().clone());

    let $list = $('#carousel_02>ul>li')

    let index1 = 0;

    let timeIds = setInterval(rightClick, 4000);

    $bannerLeft.hover(function () {
        clearInterval(timeIds);
    }, function () {
        timeIds = setInterval(rightClick, 4000);
    })

    // 右箭头
    $right.click(rightClick);
    function rightClick() {
        index1++;

        if (index1 == $list.length) {
            index1 = 1;
            $uls.css({ left: 0 });
        }

        $uls.stop().animate({ left: -index1 * $carousel_02.width() });
        $spans.eq(index1 == $list.length - 1 ? 0 : index1).addClass('active').siblings().removeClass('active');
    }
    // 点击圆点
    $spans.click(function () {
        $(this).addClass('active').siblings().removeClass('active');
        index1 = $(this).index();
        $uls.stop().animate({ left: -index1 * $carousel_02.width() });
    })
})